package com.wy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wy.entity.Address;
import com.wy.mapper.AddressMapper;
import com.wy.service.IAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.math3.analysis.function.Add;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 王昭贵
 * @since 2023-01-27
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    public List<Address> getAddrList(int id) {
        return addressMapper.selectList(new QueryWrapper<Address>().eq("customer_id", id));
    }

    @Transactional
    @Override
    public int setDeafultAddr(int id) {
        Address address = addressMapper.selectOne(new QueryWrapper<Address>().eq("selected", "1"));
        address.setSelected(0);
        addressMapper.updateById(address);
        Address address1 = new Address();
        address1.setId(id);
        address1.setSelected(1);

        return addressMapper.updateById(address1);
    }
}
